package com.zhwmall.product.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhwmall.common.entity.product.AttrAttrgroupRelationEntity;
import com.zhwmall.common.vo.AttrAttrgroupRelationVo;
import com.zhwmall.product.dao.AttrAttrgroupRelationDao;
import com.zhwmall.product.service.AttrAttrgroupRelationService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {


    @Override
    public void saveBatchByAttrGroupId(AttrAttrgroupRelationVo relation) {

        if (CollUtil.isNotEmpty(relation.getAttrIds())){
            List<AttrAttrgroupRelationEntity> collect = relation.getAttrIds().stream()
                    .map(item -> AttrAttrgroupRelationEntity.builder().attrId(item).attrGroupId(relation.getAttrGroupId()).attrSort(1).build())
                    .collect(Collectors.toList());

            baseMapper.insertBatchByAttrGroupId(collect);
        }
    }
}